package com.thunder.soft.ui.adapter;

import android.content.Intent;
import android.view.View;

import androidx.annotation.NonNull;

import com.thunder.soft.R;
import com.thunder.soft.bean.MyCollectDetailsBean;
import com.thunder.soft.common.base.BaseAdapter;
import com.thunder.soft.common.base.BaseViewHolder;
import com.thunder.soft.databinding.MyCollectItemBinding;
import com.thunder.soft.ui.activity.DetailsActivity;
import com.thunder.soft.vm.MyCollectViewModel;

import java.util.List;

public class MyCollectAdapter extends BaseAdapter<MyCollectDetailsBean, MyCollectItemBinding> {

    private static final String TAG = MyCollectAdapter.class.getName();
    private MyCollectViewModel myCollectViewModel;

    public void setMyCollectViewModel(MyCollectViewModel myCollectViewModel) {
        this.myCollectViewModel = myCollectViewModel;
    }

    @Override
    protected int layoutId(int viewType) {
        return R.layout.my_collect_item;
    }

    @Override
    protected void onBindHolder(MyCollectItemBinding binding, @NonNull BaseViewHolder<MyCollectItemBinding> holder,
                                int position, @NonNull MyCollectDetailsBean data, List<Object> payloads) {
        super.onBindHolder(binding, holder, position, data, payloads);

        binding.setMyCollectDetailsBean(getData(position));
        binding.setMyCollectViewModel(myCollectViewModel);
        binding.executePendingBindings();

        binding.myCollectItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), DetailsActivity.class);
                intent.putExtra("link", getData(position).getLink());
                v.getContext().startActivity(intent);
            }
        });
    }
}